<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <script type="text/javascript" src="${ctx}/js/jquery.js"></script>
    <script type="text/javascript" src="${ctx}/js/sapar.js"></script>
    <script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
    <script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css"/>
    <script type="text/javascript" src="${ctx}/assets/laydate/laydate.js"></script>
    <title>清洗查询</title>
    <style type="text/css">
        th, td {
            text-align: center;
        }
    </style>
</head>

<body>

<div id="saper-container">
    <div id="saper-hd"></div>
    <div id="saper-bd">
        <div class="subfiled clearfix">
            <h2>配包审核</h2>
        </div>
        <div class="subfiled-content">
            <form action="" id="peibaoShenhe">
                <!--表格开始-->
                <div id="table_left" class="table">
                    <!--表格具体内容-->
                    <div class="table-box">
                        <table>
                            <thead>
                            <tr>
                                <th><input type="checkbox"  id="quanxuan"/></th>
                                <th>配包流水</th>
                                <th>网篮条码</th>
                                <th>包条码</th>
                                <th>包名称</th>
                                <th>配包人</th>
                                <th>配包时间</th>
                                <th>审核状态</th>
                            </tr>
                            </thead>
                            <tbody class="packagedetail">
                            <c:if test="${peibaoList != null}">
                                <!-- var 是给给他起名字 -->
                                <c:forEach items="${peibaoList}" var="peibaoList">
                                    <tr data="${peibaoList.peibaoLiushui}" class="peibaodata">
                                        <td><input type="checkbox" name="key"/></td>
                                        <td>${peibaoList.peibaoLiushui }<input type="hidden" name="peibaoLiushui"
                                                                               value="${peibaoList.peibaoLiushui }"/>
                                        </td>
                                        <td>${peibaoList.qingxiWanglanTiaoma}</td>
                                        <td>${peibaoList.peibaoBaozhuangTiaoma}<input type="hidden"
                                                                                      name="peibaoBaozhuangTiaoma"
                                                                                      value="${peibaoList.peibaoBaozhuangTiaoma }"/>
                                        </td>
                                        <td>${peibaoList.qingxiWupinbaoMingcheng}</td>
                                        <td>${emMap[peibaoList.peibaoPiebaorenTiaoma]}</td>
                                        <td><fmt:formatDate value="${peibaoList.peibaoTime}"
                                                            type="date" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                        <td>
                                            <select name="peibaoHege">
                                                <option value="1">通过</option>
                                                <option value="2">不通过</option>
                                            </select>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:if>
                            </tbody>
                        </table>
                        <div id="kkpager"></div>
                        <div class="kv-item clearfix">
                            <p>
                                <span>审核人  :</span>
                                <input type="text" id="peibaoShenherenTiaoma" name="peibaoShenherenTiaoma"
                                       placeholder="审核人" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                            </p>
                        </div>
                        <a href="javascript:;" class="sapar-btn sapar-btn-recom" id="baocun">保存</a>
                    </div>
                </div><!--表格结束-->
            </form>
        </div>
    </div>
    <div id="saper-ft">
    </div>
</div>
<script type="text/javascript">
    window.onload = function () {
        $("input[name='peibaoShenherenTiaoma']").focus();
    };

    $(function () {
        var totalPage = ${total};
        var pageNo = getParameter('pageIndex');
        if (!pageNo) {
            pageNo = 1;
        }
        //生成分页
        //有些参数是可选的，比如lang，若不传有默认值
        kkpager.generPageHtml({
            pno: pageNo,
            //总页码
            total: totalPage,
            //链接前部
            hrefFormer: '${ctx}/peibao/shenheList',
            //链接尾部
            hrefLatter: '.do',
            getLink: function (n) {
                return this.hrefFormer + this.hrefLatter + "?pageIndex=" + n + "&searchTxt=" + $(".search_text").val();
            }
        });

        $("#quanxuan").live("click", function () {
            var that = $(this);
            var flag = true;
            if(that.prop('checked')){
                flag = true;
            }else{
                flag = false;
            }
            $(".packagedetail").find("input[name='key']").each(function () {
                ck = $(this);
                if (flag) {
                    ck.prop('checked', true);
                } else {
                    ck.prop('checked', false);
                }
            });
        })

        $("#baocun").click(function () {


            var ok = true;
            var ck = getSelRecord();
            if (ck.length == 0) {
                ok = false;
                alert("没有选中关包");
            }
            ck = JSON.stringify(ck);
            var person = $("#peibaoShenherenTiaoma").val();
            var pdata = {"peoplecode":person,"datas":ck};
            pdata = JSON.stringify(pdata);
            console.log(pdata);
            if(ok){
                $.ajax({
                    type: "post",
                    url: "${ctx}/peibao/peibaoshenheBaocun.do",
                    error: function () {
                        layer.alert("网络故障，稍后再试");
                    },
                    data: {"pdata": pdata},
//                data: pdata.serialise(),
                    success: function (data) {
                        if (data.status == "true") {
                            window.location.reload();
                        } else {
                            layer.msg(data.msg);
                            $("input[name='guanbaoTiaoma']").val("");
                        }
                    }
                })
            }

        });
    });

    function getSelRecord() {
        var chk_value = [];
        $('input[name="key"]:checked').each(function () {
            var state = $(this).parent().parent().find("select[name=peibaoHege]").val();
            var peibaoLiushui = $(this).parent().parent().find("input[name=peibaoLiushui]").val();
            var peibaoBaozhuangTiaoma = $(this).parent().parent().find("input[name=peibaoBaozhuangTiaoma]").val();
            var json = {"state": state, "peibaoLiushui": peibaoLiushui, "peibaoBaozhuangTiaoma": peibaoBaozhuangTiaoma};
            chk_value.push(json);
        });
        return chk_value;
    }

    function isNullOrEmpty(strVal) {
        if (strVal != null) {
            strVal = strVal.replace(/(^\s*)|(\s*$)/g, "");
        }
        if (strVal == '' || strVal == null || strVal == undefined) {
            return true;
        } else {
            return false;
        }
    }

    function getParameter(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    $(document).keydown(function (event) {
        var oPlay0 = document.getElementById("audio");
        var oPlay1 = document.getElementById("audio1");
        var peibaoShenherenTiaoma = $("input[name='peibaoShenherenTiaoma']").val();
        if (event.keyCode == 13) {
            if ($("#peibaoShenherenTiaoma").is(":focus") && !isNullOrEmpty(peibaoShenherenTiaoma)) {
                $("#baocun").click();
            }
        }
    });
</script>


</body>
</html>